package org.leetcode.middle.leetcode113;

import org.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> item = new ArrayList<>();
    public List<List<Integer>> pathSum(TreeNode root, int targetSum) {
        DFS(root,0,targetSum);
        return  res;
    }


    private void DFS(TreeNode root,int val,int target){
        if (root==null){
            return;
        }
        item.add(root.val);
        val=val+root.val;
        if (root.left==null && root.right==null && val==target){
            res.add(new ArrayList<>(item));
        }
        DFS(root.left,val,target);
        DFS(root.right,val,target);
        item.remove(item.size()-1);
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(3);
        System.out.println(list.get(0));
        list.add(0,1);
        System.out.println(list.get(0));
        System.out.println(list.get(1));
        System.out.println(list.get(2));
    }
}
